#include "common.h"

int n = 0, res;
void dfs5(TreeNode* root, int k)
{
	if (root == nullptr || n == k) return;
	dfs5(root->left, k);
	n++;
	if (n == k)
	{
		res = root->val;
		return;
	}
	dfs5(root->right, k);
}
int kthSmallest(TreeNode* root, int k)
{
	dfs5(root, k);
	return res;
}
